package com.rt.generalframework.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.rt.generalframework.core.util.PageResultUtil;
import com.rt.generalframework.dto.DictUsersDto;
import com.rt.generalframework.entity.DictUsers;
import com.rt.generalframework.mapper.DictUsersMapper;
import com.rt.generalframework.service.IDictUsersService;
import com.rt.global.ErrorCode;
import com.rt.global.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
  *
  *TODO(service层代码示例).
  *
  *<p>TODO(重点关注分页方法，和直接调用mybatisplus的方法进行增删改).
  *
  *@return
  *@author 周昭名
  *@since 2019/9/23 11:20
*/
@Service
@Slf4j
public class DictUsersServiceImpl implements IDictUsersService {

    @Resource
    DictUsersMapper dictUsersMapper;
    /**
      *
      *TODO(按主键查询).
      *
      *<p>TODO(按主键查询).
      *
      *@return
      *@author 周昭名
      *@since 2019/9/23 11:20
    */
    public DictUsers getDictUsersByStaffNo(String staffNo){
        DictUsers user = dictUsersMapper.selectById(staffNo);
        return user;
    }
    /**
      *
      *TODO(查询列表).
      *
      *<p>TODO(查询列表).
      *
      *@return
      *@author 周昭名
      *@since 2019/9/23 11:22
    */
    public List<DictUsers> getDictUsersAll(DictUsersDto dto){
        List<DictUsers> list = dictUsersMapper.geUsertList(dto);
        return list;
    }
    /**
      *
      *TODO(分页查询).
      *
      *<p>TODO(分页查询).
      *
      *@return
      *@author 周昭名
      *@since 2019/9/23 11:22
    */
    public JsonResult getDictUsersByPage(DictUsersDto dto){
        //分页查询
        Page page = PageHelper.startPage(dto.getPageNo(),dto.getPageSize());
        List<DictUsers> list = dictUsersMapper.geUsertList(dto);
        JsonResult jsonResult =  PageResultUtil.success(ErrorCode.SUCCESS.value,list,page);
        return jsonResult;
    }

    /**
     *
     *TODO(新增记录).
     *
     *<p>TODO(新增记录).
     *
     *@return
     *@author 周昭名
     *@since 2019/9/23 11:25
     */
    public int addDictUsers(DictUsers user){
        return dictUsersMapper.insert(user);
    }

    /**
      *
      *TODO(按主键更新).
      *
      *<p>TODO(按主键更新).
      *
      *@return
      *@author 周昭名
      *@since 2019/9/23 11:25
    */
    public int updateDictUsersByStaffNo(DictUsers user){
        return dictUsersMapper.updateById(user);
    }

    /**
      *
      *TODO(按主键删除).
      *
      *<p>TODO(按主键删除).
      *
      *@return
      *@author 周昭名
      *@since 2019/9/23 11:26
    */
    public int deleteDictUsersByStaffNo(String staffNo){
        return dictUsersMapper.deleteById(staffNo);
    }
}
